package top.eggcode.base;

import org.slf4j.MDC;

import java.util.UUID;

/**
 * 请求日志工具
 * Created at 2021/11/17 11:05
 *
 * @author JiaQi Ding
 * @version 1.0
 */
public final class RequestTraceUnit {

    private final static String keyName = "requestId";

    public static String createId() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    /**
     * 为请求绑定id
     */
    public static void bind() {
        MDC.put(keyName, createId());

    }

    /**
     * 销毁请求id
     */
    public static void destroy() {
        MDC.remove(keyName);
    }

    public static String getCurrentId() {
        return MDC.get(keyName);
    }
}
